<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>module.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_module_module.js.html">module.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2006 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> *
<a name="line17"></a> * @fileoverview This class supports the dynamic loading of compiled
<a name="line18"></a> * javascript modules at runtime, as descibed in the designdoc.
<a name="line19"></a> *
<a name="line20"></a> *   &lt;http://go/js_modules_design&gt;
<a name="line21"></a> *
<a name="line22"></a> */
<a name="line23"></a>
<a name="line24"></a>goog.provide(&#39;goog.module&#39;);
<a name="line25"></a>
<a name="line26"></a>goog.require(&#39;goog.array&#39;);
<a name="line27"></a>goog.require(&#39;goog.module.Loader&#39;);
<a name="line28"></a>
<a name="line29"></a>
<a name="line30"></a>/**
<a name="line31"></a> * Wrapper of goog.module.Loader.require() for use in modules.
<a name="line32"></a> * See method goog.module.Loader.require() for
<a name="line33"></a> * explanation of params.
<a name="line34"></a> *
<a name="line35"></a> * @param {string} module The name of the module. Usually, the value
<a name="line36"></a> *     is defined as a constant whose name starts with MOD_.
<a name="line37"></a> * @param {number|string} symbol The ID of the symbol. Usually, the value is
<a name="line38"></a> *     defined as a constant whose name starts with SYM_.
<a name="line39"></a> * @param {Function} callback This function will be called with the
<a name="line40"></a> *     resolved symbol as the argument once the module is loaded.
<a name="line41"></a> */
<a name="line42"></a>goog.module.require = function(module, symbol, callback) {
<a name="line43"></a>  goog.module.Loader.getInstance().require(module, symbol, callback);
<a name="line44"></a>};
<a name="line45"></a>
<a name="line46"></a>
<a name="line47"></a>/**
<a name="line48"></a> * Wrapper of goog.module.Loader.provide() for use in modules
<a name="line49"></a> * See method goog.module.Loader.provide() for explanation of params.
<a name="line50"></a> *
<a name="line51"></a> * @param {string} module The name of the module. Cf. parameter module
<a name="line52"></a> *     of method require().
<a name="line53"></a> * @param {number|string=} opt_symbol The symbol being defined, or nothing
<a name="line54"></a> *     when all symbols of the module are defined. Cf. parameter symbol of
<a name="line55"></a> *     method require().
<a name="line56"></a> * @param {Object=} opt_object The object bound to the symbol, or nothing when
<a name="line57"></a> *     all symbols of the module are defined.
<a name="line58"></a> */
<a name="line59"></a>goog.module.provide = function(module, opt_symbol, opt_object) {
<a name="line60"></a>  goog.module.Loader.getInstance().provide(
<a name="line61"></a>      module, opt_symbol, opt_object);
<a name="line62"></a>};
<a name="line63"></a>
<a name="line64"></a>
<a name="line65"></a>/**
<a name="line66"></a> * Wrapper of init() so that we only need to export this single
<a name="line67"></a> * identifier instead of three. See method goog.module.Loader.init() for
<a name="line68"></a> * explanation of param.
<a name="line69"></a> *
<a name="line70"></a> * @param {string} urlBase The URL of the base library.
<a name="line71"></a> * @param {Function=} opt_urlFunction Function that creates the URL for the
<a name="line72"></a> *     module file. It will be passed the base URL for module files and the
<a name="line73"></a> *     module name and should return the fully-formed URL to the module file to
<a name="line74"></a> *     load.
<a name="line75"></a> */
<a name="line76"></a>goog.module.initLoader = function(urlBase, opt_urlFunction) {
<a name="line77"></a>  goog.module.Loader.getInstance().init(urlBase, opt_urlFunction);
<a name="line78"></a>};
<a name="line79"></a>
<a name="line80"></a>
<a name="line81"></a>/**
<a name="line82"></a> * Produces a function that delegates all its arguments to a
<a name="line83"></a> * dynamically loaded function. This is used to export dynamically
<a name="line84"></a> * loaded functions.
<a name="line85"></a> *
<a name="line86"></a> * @param {string} module The module to load from.
<a name="line87"></a> * @param {number|string} symbol The ID of the symbol to load from the module.
<a name="line88"></a> *     This symbol must resolve to a function.
<a name="line89"></a> * @return {!Function} A function that forwards all its arguments to
<a name="line90"></a> *     the dynamically loaded function specified by module and symbol.
<a name="line91"></a> */
<a name="line92"></a>goog.module.loaderCall = function(module, symbol) {
<a name="line93"></a>  return function() {
<a name="line94"></a>    var args = arguments;
<a name="line95"></a>    goog.module.require(module, symbol, function(f) {
<a name="line96"></a>      f.apply(null, args);
<a name="line97"></a>    });
<a name="line98"></a>  };
<a name="line99"></a>};
<a name="line100"></a>
<a name="line101"></a>
<a name="line102"></a>/**
<a name="line103"></a> * Requires symbols for multiple modules, and invokes a final callback
<a name="line104"></a> * on the condition that all of them are loaded. I.e. a barrier for
<a name="line105"></a> * loading of multiple symbols. If no symbols are required, the
<a name="line106"></a> * final callback is called immediately.
<a name="line107"></a> *
<a name="line108"></a> * @param {Array.&lt;Object&gt;} symbolRequests A
<a name="line109"></a> *     list of tuples of module, symbol, callback (analog to the arguments
<a name="line110"></a> *     to require(), above). These will each be require()d
<a name="line111"></a> *     individually. NOTE: This argument will be modified during execution
<a name="line112"></a> *     of the function.
<a name="line113"></a> * @param {Function} finalCb A function that is called when all
<a name="line114"></a> *     required symbols are loaded.
<a name="line115"></a> */
<a name="line116"></a>goog.module.requireMultipleSymbols = function(symbolRequests, finalCb) {
<a name="line117"></a>  var I = symbolRequests.length;
<a name="line118"></a>  if (I == 0) {
<a name="line119"></a>    finalCb();
<a name="line120"></a>  } else {
<a name="line121"></a>    for (var i = 0; i &lt; I; ++i) {
<a name="line122"></a>      goog.module.requireMultipleSymbolsHelper_(symbolRequests, i, finalCb);
<a name="line123"></a>    }
<a name="line124"></a>  }
<a name="line125"></a>};
<a name="line126"></a>
<a name="line127"></a>
<a name="line128"></a>/**
<a name="line129"></a> * Used by requireMultipleSymbols() to load each required symbol and
<a name="line130"></a> * keep track how many are loaded, and finally invoke the barrier
<a name="line131"></a> * callback when they are all done.
<a name="line132"></a> *
<a name="line133"></a> * @param {Array.&lt;Object&gt;} symbolRequests Same as in
<a name="line134"></a> *     requireMultipleSymbols().
<a name="line135"></a> * @param {number} i The single module that is required in this invocation.
<a name="line136"></a> * @param {Function} finalCb Same as in requireMultipleSymbols().
<a name="line137"></a> * @private
<a name="line138"></a> */
<a name="line139"></a>goog.module.requireMultipleSymbolsHelper_ = function(symbolRequests, i,
<a name="line140"></a>                                                     finalCb) {
<a name="line141"></a>  var r = symbolRequests[i];
<a name="line142"></a>  var module = r[0];
<a name="line143"></a>  var symbol = r[1];
<a name="line144"></a>  var symbolCb = r[2];
<a name="line145"></a>  goog.module.require(module, symbol, function() {
<a name="line146"></a>    symbolCb.apply(this, arguments);
<a name="line147"></a>    symbolRequests[i] = null;
<a name="line148"></a>    if (goog.array.every(symbolRequests, goog.module.isNull_)) {
<a name="line149"></a>      finalCb();
<a name="line150"></a>    }
<a name="line151"></a>  });
<a name="line152"></a>};
<a name="line153"></a>
<a name="line154"></a>
<a name="line155"></a>/**
<a name="line156"></a> * Checks if the given element is null.
<a name="line157"></a> *
<a name="line158"></a> * @param {Object} el The element to check if null.
<a name="line159"></a> * @param {number} i The index of the element.
<a name="line160"></a> * @param {Array.&lt;Object&gt;} arr The array that contains the element.
<a name="line161"></a> * @return {boolean} TRUE iff the element is null.
<a name="line162"></a> * @private
<a name="line163"></a> */
<a name="line164"></a>goog.module.isNull_ = function(el, i, arr) {
<a name="line165"></a>  return el == null;
<a name="line166"></a>};
</pre>


</body>
</html>
